package com.cangxuan.manage.config;

import com.cangxuan.manage.interceptor.AdminInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    RedisTemplate<String, Object> redisTemplate;

    @Autowired
    public void setRateRedisTemplate(RedisTemplate<String, Object> redisTemplate) {
        this.redisTemplate = redisTemplate;
    }

    /**
     * 注册、配置拦截器
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new AdminInterceptor(redisTemplate))
                .addPathPatterns("/**")         //配置拦截路径
                .excludePathPatterns("/login","/swagger-ui/**","/swagger-resources/**", "/v3/**"); //配置排除路径
    }
}
